﻿Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Disabling the menu items I didn't code yet.
        menuFileSave.Enabled = False
        menuFileSaveAs.Enabled = False
        menuFileOpen.Enabled = False
        menuToolsOptions.Enabled = False
        menuHelpAbout.Enabled = False
        menuHelpHelp.Enabled = False
        menuHelpChangelog.Enabled = False
        'End of the Disabling.

        'Arrays - I really should get this moved somewhere, but I'll just leave this here for now.
        'Cvar - TimeOut
        arrayCvar(0) = "15"
        arrayCvar(1) = "20"
        arrayCvar(2) = "25"
        arrayCvar(3) = "30"
        arrayCvar(4) = "45"
        arrayCvar(5) = "60"
        arrayCvar(6) = "120"

        'RCON - 0 = BanPenalty, 1 = MaxFailures, 2 = MinFailures, 3 = MinFailureTime. Second number is the chosen index.
        arrayRcon(0, 0) = "Disabled"
        arrayRcon(0, 1) = "10"
        arrayRcon(0, 2) = "15"
        arrayRcon(0, 3) = "20"
        arrayRcon(0, 4) = "25"
        arrayRcon(0, 5) = "30"
        arrayRcon(0, 6) = "45"
        arrayRcon(0, 7) = "60"
        arrayRcon(0, 8) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 9) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 10) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 11) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 12) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 13) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 14) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(0, 15) = "Disabled //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(1, 0) = "1"
        arrayRcon(1, 1) = "2"
        arrayRcon(1, 2) = "3"
        arrayRcon(1, 3) = "4"
        arrayRcon(1, 4) = "5"
        arrayRcon(1, 5) = "6"
        arrayRcon(1, 6) = "7"
        arrayRcon(1, 7) = "8"
        arrayRcon(1, 8) = "9"
        arrayRcon(1, 9) = "10"
        arrayRcon(1, 10) = "15"
        arrayRcon(1, 11) = "20"
        arrayRcon(1, 12) = "10 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(1, 13) = "10 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(1, 14) = "10 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(2, 0) = "1"
        arrayRcon(2, 1) = "2"
        arrayRcon(2, 2) = "3"
        arrayRcon(2, 3) = "4"
        arrayRcon(2, 4) = "5"
        arrayRcon(2, 5) = "6"
        arrayRcon(2, 6) = "7"
        arrayRcon(2, 7) = "8"
        arrayRcon(2, 8) = "9"
        arrayRcon(2, 9) = "10"
        arrayRcon(2, 10) = "15"
        arrayRcon(2, 11) = "20"
        arrayRcon(2, 12) = "5 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(2, 13) = "5 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(2, 14) = "5 //Bad index chosen within arrayRcon, reverting to default"
        arrayRcon(3, 0) = "5"
        arrayRcon(3, 1) = "10"
        arrayRcon(3, 2) = "15"
        arrayRcon(3, 3) = "20"
        arrayRcon(3, 4) = "25"
        arrayRcon(3, 5) = "30"
        arrayRcon(3, 6) = "45"
        arrayRcon(3, 7) = "60"
        arrayRcon(3, 8) = "120"
        arrayRcon(3, 9) = "300"
        arrayRcon(3, 10) = "600"
        arrayRcon(3, 11) = "1200"
        arrayRcon(3, 12) = "1800"
        arrayRcon(3, 13) = "2400"
        arrayRcon(3, 14) = "3600"

        funcSettingsOpen()
    End Sub

#Region "PW Masks"
    Private Sub chkGeneralPassServerMask_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkGeneralPassServerMask.CheckedChanged
        If chkGeneralPassServerMask.Checked = True Then
            txtGeneralPassServer.UseSystemPasswordChar = True
        ElseIf chkGeneralPassServerMask.Checked = False Then
            txtGeneralPassServer.UseSystemPasswordChar = False
        Else
            txtGeneralPassServer.UseSystemPasswordChar = True
        End If
    End Sub

    Private Sub chkGeneralPassRconMask_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkGeneralPassRconMask.CheckedChanged
        If chkGeneralPassRconMask.Checked = True Then
            txtGeneralPassRcon.UseSystemPasswordChar = True
        ElseIf chkGeneralPassRconMask.Checked = False Then
            txtGeneralPassRcon.UseSystemPasswordChar = False
        Else
            txtGeneralPassRcon.UseSystemPasswordChar = True
        End If
    End Sub
#End Region

#Region "Menu toolstrip items"
    Private Sub menuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuFileExit.Click
        Me.Dispose()
        Me.Close()
    End Sub

    Private Sub menuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuFileOpen.Click
        'Disabled in frmMain_Load event.
    End Sub

    Private Sub menuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuFileSave.Click
        'Disabled in frmMain_Load event.
    End Sub

    Private Sub menuFileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuFileSaveAs.Click
        'Disabled in frmMain_Load event.
    End Sub

    Private Sub menuToolsOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuToolsOptions.Click
        'Disabled in frmMain_Load event.
    End Sub

    Private Sub menuToolsDefaultsOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuToolsDefaultsOpen.Click
        funcSettingsOpen()
    End Sub

    Private Sub menuToolsDefaultsSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuToolsDefaultsSave.Click
        If funcMsgWarning("Doing this overwrites the current settings." & vbCrLf & vbCrLf & "Are you sure you want to continue?") = MsgBoxResult.Ok Then
            funcSettingsSave()
        End If
    End Sub

    Private Sub menuToolsDefaultsReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuToolsDefaultsReset.Click
        If funcMsgWarning("If you changed the default settings, this will discard those changes. This can not be undone." & vbCrLf & vbCrLf & "Are you sure you want to do this?") = MsgBoxResult.Ok Then
            funcSettingsReset()
            If funcMsgQuestion("Do you want to load the Default Settings as well?" & vbCrLf & vbCrLf & "Press cancel to keep the current settings.") = MsgBoxResult.Ok Then
                funcSettingsOpen()
            End If
        End If
    End Sub

    Private Sub menuHelpHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuHelpHelp.Click
        'Disabled in frmMain_Load event.

    End Sub

    Private Sub menuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuHelpAbout.Click
        'Disabled in frmMain_Load event.
    End Sub

    Private Sub menuHelpChangelog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuHelpChangelog.Click
        'Disabled in frmMain_Load event.
    End Sub
#End Region

    Private Sub btnViewCfg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewCfg.Click

        'These variables are used to check if things are filled in or enabled.
        'If not, it will produce warnings and errors to notify the user of the problem.
        Dim filledName As Boolean
        Dim filledPass As Boolean
        Dim filledRcon As Boolean
        Dim filledContact As Boolean
        Dim FinalCase As Integer = 0 'This is used in the following cases. Short: 0=Non, 1=Server Name, 2=RCON Password, 4=Contact Email, 8=Server Password. Done binary so just add them up and you got your outcome :)

        Select Case txtGeneralServerName.Text
            Case ""
                filledName = False
            Case Else
                filledName = True
                FinalCase += 1
        End Select

        Select Case txtGeneralPassRcon.Text
            Case ""
                filledRcon = False
            Case Else
                filledRcon = True
                FinalCase += 2
        End Select

        Select Case txtGeneralContact.Text
            Case ""
                filledContact = False
            Case Else
                filledContact = True
                FinalCase += 4
        End Select

        Select Case txtGeneralPassServer.Text
            Case ""
                filledPass = False
            Case Else
                filledPass = True
                FinalCase += 8
        End Select

        'This is checking what's filled in and what's not. Will produce errors/warnings/questions accordingly. 
        Select Case FinalCase
            Case 0, 2, 4, 6, 8, 10, 12, 14 'xxx0 (Anything that doesn't have the Server Name filled in.
                funcMsgError("Please enter a name for the server (Server Name)")
            Case 1 '0001
                If funcMsgWarning("You haven't filled in an RCON password, are you sure you want this disabled?") = MsgBoxResult.Ok Then
                    If funcMsgQuestion("No E-Mail address for contact has been filled in, are you sure you don't want this enabled?") = MsgBoxResult.Ok Then
                        frmView.ShowDialog()
                    End If
                End If
            Case 3 '0011
                If funcMsgQuestion("No E-Mail address for contact has been filled in, are you sure you don't want this enabled?") = MsgBoxResult.Ok Then
                    frmView.ShowDialog()
                End If
            Case 5 '0101
                If funcMsgWarning("You haven't filled in an RCON password, are you sure you want this disabled?") = MsgBoxResult.Ok Then
                    frmView.ShowDialog()
                End If
            Case 7 '0111
                'Everything is fine, only the server password isn't filled in, which isn't an issue. Just using this because I have case else occupied.
                frmView.ShowDialog()
            Case 9 '1001
                If funcMsgWarning("You haven't filled in an RCON password, are you sure you want this disabled?") = MsgBoxResult.Ok Then
                    If funcMsgQuestion("No E-Mail address for contact has been filled in, are you sure you don't want this enabled?") = MsgBoxResult.Ok Then
                        If funcMsgQuestion("You have a the Server Password enabled, this means people can only join the server if they know the password, are you sure you want this enabled?") = MsgBoxResult.Ok Then
                            frmView.ShowDialog()
                        End If
                    End If
                End If
            Case 11 '1011
                If funcMsgQuestion("No E-Mail address for contact has been filled in, are you sure you don't want this enabled?") = MsgBoxResult.Ok Then
                    If funcMsgQuestion("You have a the Server Password enabled, this means people can only join the server if they know the password, are you sure you want this enabled?") = MsgBoxResult.Ok Then
                        frmView.ShowDialog()
                    End If
                End If
            Case 13 '1101
                If funcMsgWarning("You haven't filled in an RCON password, are you sure you want this disabled?") = MsgBoxResult.Ok Then
                    If funcMsgQuestion("You have a the Server Password enabled, this means people can only join the server if they know the password, are you sure you want this enabled?") = MsgBoxResult.Ok Then
                        frmView.ShowDialog()
                    End If
                End If
            Case 15 '1111
                If funcMsgQuestion("You have a the Server Password enabled, this means people can only join the server if they know the password, are you sure you want this enabled?") = MsgBoxResult.Ok Then
                    frmView.ShowDialog()
                End If
            Case Else
                funcMsgError("Something went wrong, please contact the Developer at: dalekjace@gmail.com!")
                'Shouldn't ever happen, but thought it'd be smart to add, just in case.
        End Select
        'End of this, cases are so much better and neater then if...else statements :O
    End Sub
End Class
